<template>
  <div>
    {{ msg }}
    <br />
    <input v-model="msg" />
  </div>
</template>

<script setup lang="ts">
  import { customRef } from 'vue'

  let value = ''
  /**
   * @description: 自定义ref
   * @param {*} customRef
   * @param {*} track 跟踪器
   * @param {*} trigger 触发器
   * @return {*}
   */
  let msg = customRef((track, trigger) => {
    return {
      get() {
        track()
        return value
      },
      set(newValue) {
        console.log('set--', newValue)
        value = newValue
        trigger()
      }
    }
  })
</script>

<style>
</style>